# 模拟12306购票
dict_ticket = {
    "G1569": ("北京南-天津南", "18:06", "18:39", "00:33"),
    "G1567": ("北京南-天津南", "18:15", "18:49", "00:34"),
    "G8917": ("北京南-天津西", "18:20", "18:19", "00:59"),
    "G203": ("北京南-天津南", "18:35", "19:09", "00:34"),
}


# length calculation function
def visual_len(s):
    return sum(2 if ord(c) > 127 else 1 for c in s)


# complete function
def pad(s, width):
    delta = width - visual_len(s)
    return s + " " * max(delta, 0)


# 3. 列宽（显示宽度）
COL = [10, 16, 10, 10, 10]  # 车次 线路 出发 到达 历时

# 4. 表头
header = (
    pad("车次", COL[0])
    + pad("线路", COL[1])
    + pad("出发时间", COL[2])
    + pad("到达时间", COL[3])
    + pad("历时", COL[4])
)

print(header)
print("-" * visual_len(header))

for train, info in dict_ticket.items():
    line, departure, arrival, duration = info
    row = (
        pad(train, COL[0])
        + pad(line, COL[1])
        + pad(departure, COL[2])
        + pad(arrival, COL[3])
        + pad(duration, COL[4])
    )
    print(row)

# 输入用户购票车次
train_no = input("请输入需要购买的车次：")
train_info = dict_ticket.get(train_no, "车次不存在！")
if train_info != "车次不存在！":
    person = input("请输入购票人姓名，如多个购票人，请用逗号分隔：")
    print(
        "您已购买了"
        + train
        + " "
        + line
        + departure
        + "开"
        + "，请"
        + person
        + "尽快换取纸质车票，【Orange】"
    )
else:
    print("您输入的车次不存在！")
